<template>
  <view>
    <scroll-view
      class="will-service"
      scroll-y="true"
      @scrolltolower="reachBottom"
      v-if="orderInfoList.length > 0"
    >
      <OrderInfo
        v-for="(item, index) in orderInfoList"
        :key="index"
        :itemInfo="item"
        :isFinishEstimate="false"
        @click.native="orderInfoHandleClick(item)"
      />
    </scroll-view>
    <Empty
      v-else
      :baseImg="emptyImg"
      text="暂无相关数据~"
      :fontWeight="400"
      class="empty"
    />
  </view>
</template>

<script>
import {
  getConsultantBindPersonList,
  updateConsultantNoticeStatus,
} from "@/api/modules/orderManage.js";

import OrderInfo from "../cpn/orderInfo.vue";
import Empty from "@/components/Empty.vue";

export default {
  components: { OrderInfo, Empty },
  props: {
    cardType: {
      type: String,
      default: "",
    },
    matchTitle: {
      type: String,
      default: "",
    },
  },
  watch: {
    cardType(newVal, oldVal) {
      this.pageNo = 1;
      this.orderInfoList = [];
      this.getConsultantBindPersonListFn();
    },
    matchTitle(newVal, oldVal) {
      this.pageNo = 1;
      this.orderInfoList = [];
      this.getConsultantBindPersonListFn();
    },
  },
  data() {
    return {
      orderInfoList: [],
      pageNo: 1, // 分页页码
      emptyImg: this.$imgBaseSelf + "common/empty.png",
    };
  },
  methods: {
    orderInfoHandleClick(item) {
      if (item.noticeStatus == "2") {
        this.updateConsultantNoticeStatusFn(item.noticeId);
      }
      uni.navigateTo({
        url:
          "/pagesSub/orderManageForFree/orderInfo/index?itemInfo=" +
          JSON.stringify(item) +
          "&originFrom=" +
          "willService",
      });
    },
    async getConsultantBindPersonListFn() {
      const params = {
        searchType: "10",
        consultantId: uni.getStorageSync("person-id").slice(2),
        pageSize: 10,
        pageNo: this.pageNo,
        cardType: this.cardType,
        matchTitle: this.matchTitle,
      };
      const res = await getConsultantBindPersonList(params);
      if (res.code == 200) {
        this.orderInfoList = this.orderInfoList.concat(res.data);
        // this.orderInfoList.forEach((item, index) => {
        //   let tempName = "";
        //   let tempDesc = "";
        //   item.orderProductList.forEach((_item, _index) => {
        //     if (tempName == "") {
        //       tempName = tempName + _item.orderFuncName;
        //     } else {
        //       tempName = tempName + "、" + _item.orderFuncName;
        //     }
        //     tempDesc = tempDesc + _item.productDesc;
        //   });
        //   item.rightProducts = tempName;
        //   item.productDesc = tempDesc;
        // });
      }
    },
    async updateConsultantNoticeStatusFn(id) {
      const params = {
        id: id,
        cnReadStatus: 1,
      };
      const res = await updateConsultantNoticeStatus(params);
    },
    reachBottom() {
      this.pageNo += 1;
      this.getConsultantBindPersonListFn();
    },
  },
  created() {
    this.getConsultantBindPersonListFn();
  },
};
</script>

<style lang="scss" scoped>
.will-service {
  // display: flex;
  // flex-direction: column;
  // align-items: center;
  // overflow-y: scroll;
  // height: 85vh;
  height: calc(100vh - 430rpx);
}
</style>
